﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using EnglishStudy.ViewModel;
using EnglishStudy.Entity;

namespace EnglishStudy.View
{
    public partial class LessonPage : PhoneApplicationPage
    {
        public LessonPage()
        {
            InitializeComponent();
            try
            {
                // Set the page DataContext property to the ViewModel.
                this.DataContext = App.ViewModel;

       
                lb_Lesson.SelectionChanged += listWord_SelectionChanged;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            
        }

        void listWord_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lb_Lesson.SelectedIndex != -1)
            {
                var lessonItem = sender as ListBox;
                var a = lessonItem.SelectedItem as LessonItem;
                PhoneApplicationService.Current.State["lessonEntity"] = a;
                lb_Lesson.SelectedIndex = -1;
                NavigationService.Navigate(new Uri("/View/Study.xaml", UriKind.Relative));
            }
        }
    }
}